package com.home766.controller.admin;

import com.home766.dto.DictionaryDTO;
import com.home766.entity.Scheme;
import com.home766.entity.SchemeImage;
import com.home766.entity.SchemeProduct;
import com.home766.service.*;
import com.home766.util.DateTime;
import com.home766.util.StringUtil;
import net.biz.FileInfo.FileType;
import net.biz.Filter;
import net.biz.Filter.Operator;
import net.biz.Message;
import net.biz.Message.Type;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.controller.admin.BaseController;
import net.biz.service.AdminService;
import net.biz.service.FileService;
import net.biz.service.SnService;
import net.biz.service.TagService;
import net.biz.util.JsonUtils;
import net.biz.util.ParamsUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * 方案-controller
 */
@Controller
@RequestMapping("/admin/scheme")
public class SchemeController extends BaseController {
	
	private final static String VIEW_SCHEME_LIST = "/admin/scheme/list";
	private final static String VIEW_SCHEME_ADD = "/admin/scheme/add";
	private final static String VIEW_SCHEME_EDIT = "/admin/scheme/edit";
	private final static String VIEW_SCHEME_DETAIL = "/admin/scheme/detail";
	
	@Resource(name="schemeServiceImpl")
	private SchemeService schemeService;
	@Resource(name = "tagServiceImpl")
	private TagService tagService;
	@Resource(name="snServiceImpl")
	private SnService snService;
	@Resource(name="adminServiceImpl")
	private AdminService adminService;
	@Autowired
	private IDictionaryService iDictionaryService;
	@Resource(name="schemeProductServiceImpl")
	private SchemeProductService schemeProductService;
	@Resource(name = "schemeImageServiceImpl")
	private SchemeImageService schemeImageService;
	@Resource(name = "schemeConstructImageServiceImpl")
	private SchemeConstructImageService schemeConstructImageService;
	@Resource(name = "fileServiceImpl")
	private FileService fileService;
	
	@Value("${date_yyyy_mm_dd_format}")
	private String DATE_YYYY_MM_DD_FORMAT;
	/**
	 * 检查名称是否存在
	 * @param name
	 * @return
	 */
	@RequestMapping(value="/check_exist",method =RequestMethod.GET)
	@ResponseBody
	public boolean checkExists(String name){
		if (StringUtils.isEmpty(name)) {
			return false;
		}
		if (schemeService.checkExists(name)) {
			return false;
		} else {
			return true;
		}
	}
	
	/**
	 * 方案列表分页查询(带查询条件)
	 * @param pageable
	 * @param sn            方案编码
	 * @param name          方案名称
	 * @param createPerson  创建人
	 * @param createDate    创建时间
	 * @param type          方案类型
	 * @param isMarketable  是否已上架
	 * @return
	 */
	@RequestMapping(value="/list",method = RequestMethod.GET)
	public String list(Pageable pageable, ModelMap model){
		Filter filter = new Filter();
		filter.setProperty("isDelete");
		filter.setValue(false);
		filter.setOperator(Operator.eq);
		pageable.getFilters().add(filter);
		Page<Scheme> page = schemeService.findPage(pageable);
		model.addAttribute("page", page);
		List<DictionaryDTO> types = iDictionaryService.searchChildren(ParamsUtil.SCHEME_TYPE);
		model.addAttribute("types", types);
		return VIEW_SCHEME_LIST;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(ModelMap model) {
		//查询属性值
		List<DictionaryDTO> schemeAttrs = iDictionaryService.searchChildren(ParamsUtil.SCHEME_ATTRIBUTE);
		//查询面积范围属性标签值
		List<DictionaryDTO> areaTags = iDictionaryService.searchChildren(ParamsUtil.SCHEME_AREA_TAG);
		List<DictionaryDTO> types = iDictionaryService.searchChildren(ParamsUtil.SCHEME_TYPE);
		model.addAttribute("types", types);
		model.addAttribute("schAttrs", schemeAttrs);
		model.addAttribute("areaTags", areaTags);
		return VIEW_SCHEME_ADD;
	}
	
	/**
	 * 编辑
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public String edit(ModelMap model, Long id) {
		if(id == null){
			return ERROR_VIEW;
		}
		Scheme scheme = schemeService.find(id);
		if(scheme == null){
			return ERROR_VIEW;
		}
		List<SchemeProduct> sps = scheme.getSchemeProducts();
		String schemeProductIds = "";
		if(sps.size() > 0){
			for(SchemeProduct sp : sps){
				schemeProductIds = schemeProductIds + sp.getId() + ",";
			}
		}
		if(!StringUtil.isNullOrSpace(schemeProductIds)){
			schemeProductIds = schemeProductIds.substring(0,schemeProductIds.length()-1);
		}
		model.addAttribute("schemeProductIds", schemeProductIds);
		//根据方案id查询方案信息
		model.addAttribute("scheme", scheme);
		//查询对应类型的属性值
		List<DictionaryDTO> schemeAttrs = iDictionaryService.searchChildren(ParamsUtil.SCHEME_ATTRIBUTE);
		List<DictionaryDTO> categorys = iDictionaryService.searchChildren(scheme.getType());
		//查询面积范围属性标签值
		List<DictionaryDTO> areaTags = iDictionaryService.searchChildren(ParamsUtil.SCHEME_AREA_TAG);
		List<DictionaryDTO> types = iDictionaryService.searchChildren(ParamsUtil.SCHEME_TYPE);
		model.addAttribute("types", types);
		model.addAttribute("schAttrs", schemeAttrs);
		model.addAttribute("areaTags", areaTags);
		model.addAttribute("categorys", categorys);
		return VIEW_SCHEME_EDIT;
	}
	
	/**
	 * 详情查看
	 */
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public String detail(ModelMap model, Long id) {
		if(id == null){
			return ERROR_VIEW;
		}
		Scheme scheme = schemeService.find(id);
		if(scheme == null){
			return ERROR_VIEW;
		}
		//根据方案id查询方案信息
		model.addAttribute("scheme", scheme);
		model.addAttribute("tags", tagService.findList(net.biz.entity.Tag.Type.product));
		//查询对应类型的属性值
		List<DictionaryDTO> schemeAttrs = iDictionaryService.searchChildren(ParamsUtil.SCHEME_ATTRIBUTE);
		List<DictionaryDTO> dValues = iDictionaryService.searchChildren(ParamsUtil.SCHEME_TYPE);
		//查询面积范围属性标签值
		List<DictionaryDTO> areaTags = iDictionaryService.searchChildren(ParamsUtil.SCHEME_AREA_TAG);
		model.addAttribute("schAttrs", schemeAttrs);
		model.addAttribute("dValues", dValues);
		model.addAttribute("areaTags", areaTags);
		return VIEW_SCHEME_DETAIL;
	}
	
	/**
	 * 保存
	 * @param model
	 * @param scheme
	 * @return
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String save(String upDate, String downDate, Scheme scheme, Long[] spIds, Integer[] schemeAttr, RedirectAttributes redirectAttributes) {
		if(scheme == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"数据信息获取失败！"));
			return ERROR_VIEW;
		}
		if(spIds == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"未选择主材产品！"));
			return ERROR_VIEW;
		}
		List<SchemeProduct> schemeProducts = schemeProductService.findList(spIds);
		if(schemeProducts.size() == 0){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"材产品数据信息获取失败！"));
			return ERROR_VIEW;
		}
		//方案图片验证及上传
		for (Iterator<SchemeImage> iterator = scheme.getSchemeImages().iterator(); iterator.hasNext();) {
			SchemeImage schemeImage = iterator.next();
			if (schemeImage == null || schemeImage.isEmpty()) {
				iterator.remove();
				continue;
			}
			if (schemeImage.getFile() != null && !schemeImage.getFile().isEmpty()) {
				if (!fileService.isValid(FileType.image, schemeImage.getFile())) {
					addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid"));
					return "redirect:add.jhtml";
				}
			}
		}
		for (SchemeImage schemeImage : scheme.getSchemeImages()) {
			schemeImageService.build(schemeImage);
		}
		//方案施工图片验证及上传
//		for (Iterator<SchemeConstructImage> iterator = scheme.getConstructImages().iterator(); iterator.hasNext();) {
//			SchemeConstructImage constructImage = iterator.next();
//			if (constructImage == null || constructImage.isEmpty()) {
//				iterator.remove();
//				continue;
//			}
//			if (constructImage.getFile() != null && !constructImage.getFile().isEmpty()) {
//				if (!fileService.isValid(FileType.image, constructImage.getFile())) {
//					addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid"));
//					return "redirect:add.jhtml";
//				}
//			}
//		}
//		for (SchemeConstructImage constructImage : scheme.getConstructImages()) {
//			schemeConstructImageService.build(constructImage);
//		}
		Collections.sort(scheme.getSchemeImages());
		if(!StringUtil.isNullOrSpace(upDate)){
			Date date=DateTime.getDate(upDate,DATE_YYYY_MM_DD_FORMAT);
			scheme.setUpDate(date);
		}
		if(!StringUtil.isNullOrSpace(downDate)){
			Date date=DateTime.getDate(downDate,DATE_YYYY_MM_DD_FORMAT);
			scheme.setDownDate(date);
		}
		scheme.setSchemeImages(scheme.getSchemeImages());
//		scheme.setConstructImages(scheme.getConstructImages());
		scheme.setSchemeProducts(schemeProducts);
		scheme.setCreateDate(new Date());
		scheme.setModifyDate(new Date());
		scheme.setIsDelete(false);
		//外机默认1
		scheme.setOutNumber(1);
		scheme.setSn(snService.generate(net.biz.entity.Sn.Type.scheme));
		scheme.setCreatePerson(adminService.getCurrentUsername());
		if(scheme.getIsTehui() == null || !scheme.getIsTehui()){
			scheme.setTehuiTitle(null);			
		}
		//设置方案价格
		BigDecimal price = BigDecimal.ZERO;
		if(scheme.getInstallCost() == null || scheme.getAuxiliaryUnitPrice() == null || scheme.getAcreage() == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"安装费用、辅材单价或面积信息填写不完整！"));
			return ERROR_VIEW;
		}
		//辅材单价
		BigDecimal unitprice = scheme.getAuxiliaryUnitPrice();
		//安装费
		BigDecimal cost = scheme.getInstallCost();
		//面积
		BigDecimal acreage = new BigDecimal(scheme.getAcreage());
		//判断是暖气还是空调
		if(scheme.getType() == ParamsUtil.SCHEME_PRODUCT_ID_ZNNQ){
			price = acreage.multiply(unitprice.add(cost)).setScale(2, BigDecimal.ROUND_HALF_UP);
			//智能暖气
			for(SchemeProduct sp : schemeProducts){
				//产品单价
				BigDecimal spprice = sp.getPrice();
				//系数
				Double coeff = sp.getCoefficient();
				//类型区分值
				Integer distType = sp.getDistType();
				if(sp.getPrice() != null){
					if(distType == 1){
						//有系数
						BigDecimal finalPrice = acreage.multiply(spprice).multiply(new BigDecimal(coeff)).setScale(2, BigDecimal.ROUND_HALF_UP);
						price = price.add(finalPrice);
					}else if(distType == 2){
						//无系数且不是自选商品
						price = price.add(sp.getPrice());						
					}
//					else if(distType == 3){
//						//自选商品,商品价不计入方案总价里
//						
//					}
				}
			}
		}else if(scheme.getType() == ParamsUtil.SCHEME_PRODUCT_ID_ZNKT){
			//智能空调
			Integer inNum = scheme.getInNumber();
			if(inNum == null){
				//内机数量为空
				return ERROR_VIEW;
			}
			//计算安装费
			//外机和内机个数和
			scheme.setOutNumber(1);
			Integer num = scheme.getOutNumber() + scheme.getInNumber();
			//安装费
			BigDecimal anzfei = cost.multiply(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_HALF_UP);
			price = price.add(anzfei);
			//计算辅材费
			BigDecimal fucfei = unitprice.multiply(new BigDecimal(inNum)).setScale(2, BigDecimal.ROUND_HALF_UP);
			price = price.add(fucfei);
			
			for(SchemeProduct sp : schemeProducts){
				//产品单价
				BigDecimal spprice = sp.getPrice();
				//类型区分值
				Integer distType = sp.getDistType();
				if(spprice != null){
					if(distType != 3){
						price = price.add(spprice);
					}
				}
			}
		}
		scheme.setPrice(price);
//		//计算方案最终价格
//		for(SchemeProduct sp : schemeProducts){
//			if(sp.getPrice() != null){
//				price = price.add(sp.getPrice());				
//			}
//		}
//		scheme.setPrice(price);
		//设置方案属性
		String attr = "";
		for (int i = 0; i < schemeAttr.length; i++) {
			attr += schemeAttr[i].intValue() + ",";
		}
		if(!StringUtil.isNullOrSpace(attr)){
			attr = attr.substring(0, attr.length() - 1);
		}
		scheme.setAttribute(attr);
		try {
			//保存方案数据
			schemeService.save(scheme);
			addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
			return "redirect:list.jhtml";
		} catch (Exception e) {
			e.printStackTrace();
			addFlashMessage(redirectAttributes, new Message(Type.warn,"保存失败，出现异常！"));
			return ERROR_VIEW;
		}
	}
	
	/**
	 * 更新
	 * @param model
	 * @param scheme
	 * @return
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public String update(String upDate, String downDate, Scheme scheme, Long[] spIds, Integer[] schemeAttr, RedirectAttributes redirectAttributes) {
		if(scheme == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"数据信息获取失败！"));
			return ERROR_VIEW;
		}
		if(spIds == null || spIds.length == 0){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"未选择主材产品！"));
			return ERROR_VIEW;
		}
		List<SchemeProduct> schemeProducts = schemeProductService.findList(spIds);
		if(schemeProducts.size() == 0){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"材产品数据信息获取失败！"));
			return ERROR_VIEW;
		}
		for (Iterator<SchemeImage> iterator = scheme.getSchemeImages().iterator(); iterator.hasNext();) {
			SchemeImage schemeImage = iterator.next();
			if (schemeImage == null || schemeImage.isEmpty()) {
				iterator.remove();
				continue;
			}
			if (schemeImage.getFile() != null && !schemeImage.getFile().isEmpty()) {
				if (!fileService.isValid(FileType.image, schemeImage.getFile())) {
					addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid"));
					return "redirect:edit.jhtml?id="+scheme.getId();
				}
			}
		}
		for (SchemeImage schemeImage : scheme.getSchemeImages()) {
			schemeImageService.build(schemeImage);
		}
		//方案施工图片验证及上传
//		for (Iterator<SchemeConstructImage> iterator = scheme.getConstructImages().iterator(); iterator.hasNext();) {
//			SchemeConstructImage constructImage = iterator.next();
//			if (constructImage == null || constructImage.isEmpty()) {
//				iterator.remove();
//				continue;
//			}
//			if (constructImage.getFile() != null && !constructImage.getFile().isEmpty()) {
//				if (!fileService.isValid(FileType.image, constructImage.getFile())) {
//					addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid"));
//					return "redirect:edit.jhtml?id="+scheme.getId();
//				}
//			}
//		}
//		for (SchemeConstructImage constructImage : scheme.getConstructImages()) {
//			schemeConstructImageService.build(constructImage);
//		}
		Collections.sort(scheme.getSchemeImages());
		Scheme s = schemeService.find(scheme.getId());
		if(s == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"获取方案数据失败！"));
			return ERROR_VIEW;
		}
		if(!StringUtil.isNullOrSpace(upDate)){
			Date date=DateTime.getDate(upDate,DATE_YYYY_MM_DD_FORMAT);
			s.setUpDate(date);
		}else{
			s.setUpDate(null);
		}
		if(!StringUtil.isNullOrSpace(downDate)){
			Date date=DateTime.getDate(downDate,DATE_YYYY_MM_DD_FORMAT);
			s.setDownDate(date);
		}else{
			s.setDownDate(null);
		}
		s.setSchemeImages(scheme.getSchemeImages());
//		s.setConstructImages(scheme.getConstructImages());
		s.setSchemeProducts(schemeProducts);
		s.setType(scheme.getType());
		s.setCategory(scheme.getCategory());
		s.setName(scheme.getName());
		s.setAuxiliaryUnitPrice(scheme.getAuxiliaryUnitPrice());
		s.setAcreage(scheme.getAcreage());
		s.setImage(scheme.getImage());
		s.setInstallCost(scheme.getInstallCost());
		s.setIsGift(scheme.getIsGift());
		s.setIsList(scheme.getIsList());
		s.setIsMarketable(scheme.getIsMarketable());
		s.setIsTop(scheme.getIsTop());
		s.setKeyword(scheme.getKeyword());
		s.setSeoTitle(scheme.getSeoTitle());
		s.setIntroduction(scheme.getIntroduction());
		s.setPriceDescript(scheme.getPriceDescript());
		s.setParameter(scheme.getParameter());
		s.setConfiguration(scheme.getConfiguration());
		s.setAuxiliaryDescript(scheme.getAuxiliaryDescript());
		s.setInstallStandard(scheme.getInstallStandard());
		s.setBeginArea(scheme.getBeginArea());
		s.setEndArea(scheme.getEndArea());
		s.setAreaTag(scheme.getAreaTag());
		s.setIsTehui(scheme.getIsTehui());
		s.setIsChange(scheme.getIsChange());
		s.setInNumber(scheme.getInNumber());
		if(scheme.getIsTehui() != null && scheme.getIsTehui()){
			s.setTehuiTitle(scheme.getTehuiTitle());
		}else{
			s.setTehuiTitle(null);			
		}
		//设置方案价格
		BigDecimal price = BigDecimal.ZERO;
		if(scheme.getInstallCost() == null || scheme.getAuxiliaryUnitPrice() == null || scheme.getAcreage() == null){
			addFlashMessage(redirectAttributes, new Message(Type.warn,"安装费用、辅材单价或面积信息填写不完整！"));
			return ERROR_VIEW;
		}
		//辅材单价
		BigDecimal unitprice = scheme.getAuxiliaryUnitPrice();
		//安装费
		BigDecimal cost = scheme.getInstallCost();
		//面积
		BigDecimal acreage = new BigDecimal(scheme.getAcreage());
		//判断是暖气还是空调
		if(scheme.getType() == ParamsUtil.SCHEME_PRODUCT_ID_ZNNQ){
			price = acreage.multiply(unitprice.add(cost)).setScale(2, BigDecimal.ROUND_HALF_UP);
			//智能暖气
			for(SchemeProduct sp : schemeProducts){
				//产品单价
				BigDecimal spprice = sp.getPrice();
				//系数
				Double coeff = sp.getCoefficient();
				//类型区分值
				Integer distType = sp.getDistType();
				if(sp.getPrice() != null){
					if(distType == 1){
						//有系数
						BigDecimal finalPrice = acreage.multiply(spprice).multiply(new BigDecimal(coeff)).setScale(2, BigDecimal.ROUND_HALF_UP);
						price = price.add(finalPrice);
					}else if(distType == 2){
						//无系数且不是自选商品
						price = price.add(sp.getPrice());						
					}
//					else if(distType == 3){
//						//自选商品,商品价不计入方案总价里
//						
//					}
				}
			}
		}else if(scheme.getType() == ParamsUtil.SCHEME_PRODUCT_ID_ZNKT){
			//智能空调
			Integer inNum = scheme.getInNumber();
			if(inNum == null){
				//内机数量为空
				return ERROR_VIEW;
			}
			//计算安装费
			//外机和内机个数和
			Integer num = s.getOutNumber() + scheme.getInNumber();
			//安装费
			BigDecimal anzfei = cost.multiply(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_HALF_UP);
			price = price.add(anzfei);
			//计算辅材费
			BigDecimal fucfei = unitprice.multiply(new BigDecimal(inNum)).setScale(2, BigDecimal.ROUND_HALF_UP);
			price = price.add(fucfei);
			
			for(SchemeProduct sp : schemeProducts){
				//产品单价
				BigDecimal spprice = sp.getPrice();
				//类型区分值
				Integer distType = sp.getDistType();
				if(spprice != null){
					if(distType != 3){
						price = price.add(spprice);
					}
				}
			}
		}
		s.setPrice(price.setScale(2, BigDecimal.ROUND_HALF_UP));
//		BigDecimal price = null;
//		if(scheme.getInstallCost() == null || scheme.getAuxiliaryUnitPrice() == null || scheme.getAcreage() == null){
//			addFlashMessage(redirectAttributes, new Message(Type.warn,"安装费用、辅材单价或面积信息填写不完整！"));
//			return ERROR_VIEW;
//		}
//		//辅材单价
//		BigDecimal unitprice = scheme.getAuxiliaryUnitPrice();
//		//安装费
//		BigDecimal cost = scheme.getInstallCost();
//		//面积
//		BigDecimal acreage = new BigDecimal(scheme.getAcreage());
//		price = acreage.multiply(unitprice.add(cost));
//		//计算方案最终价格
//		for(SchemeProduct sp : schemeProducts){
//			if(sp.getPrice() != null){
//				price = price.add(sp.getPrice());				
//			}
//		}
//		s.setPrice(price);
		//设置方案属性
		String attr = "";
		for (int i = 0; i < schemeAttr.length; i++) {
			attr += schemeAttr[i].intValue() + ",";
		}
		if(!StringUtil.isNullOrSpace(attr)){
			attr = attr.substring(0, attr.length() - 1);
		}
		s.setAttribute(attr);
		try {
			//保存方案数据
			schemeService.update(s);
			addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
			return "redirect:list.jhtml";
		} catch (Exception e) {
			e.printStackTrace();
			addFlashMessage(redirectAttributes, new Message(Type.warn,"保存失败，出现异常！"));
			return ERROR_VIEW;
		}
	}
	
	/**
	 * 删除
	 * @param model
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public Message delete(ModelMap model, Long[] ids) {
		if(ids == null || ids.length == 0){
			return new Message(Type.warn,"请选择需要删除的数据！");
		}
		try {
			schemeService.delete(ids);
			return SUCCESS_MESSAGE;
		} catch (Exception e) {
			e.printStackTrace();
			return new Message(Type.warn,"删除过程出现异常！");
		}
	}
	
	/**
	 * 根据方案所属类型查询对应主材产品数据
	 * @param type 类型
	 * @return
	 */
	@RequestMapping(value = "/findSchemeProduct", method = RequestMethod.POST)
	@ResponseBody
	public String findSchemeProduct(Long type, String sn, String name) {
		if(type == null){
			return null;
		}
		//根据方案类型查询对应方案产品数据集合
		List<SchemeProduct> sps = schemeProductService.findSchemeProductByCategory(type,sn,name);
		return JsonUtils.toJson(sps);
	}
	
	/**
	 * 根据方案类型查询分类
	 * @param type
	 * @return
	 */
	@RequestMapping(value = "/findSchemeCategoryByType", method = RequestMethod.POST)
	@ResponseBody
	public String findSchemeCategoryByType(Long type) {
		if(type == null){
			return null;
		}
		//根据方案类型查询对应方案产品数据集合
		List<DictionaryDTO> dtos = iDictionaryService.searchChildren(type);
		return JsonUtils.toJson(dtos);
	}
	
}
